from django.db import models

# Create your models here.
# 股票基本信息
class Basic(models.Model):
    ts_code = models.CharField('TS代码', max_length=20, db_index=True)
    symbol = models.CharField('股票代码', max_length=12, db_index=True)
    name = models.CharField('股票名称', max_length=24, db_index=True)
    area = models.CharField('所在地域', max_length=12)
    industry = models.CharField('所属行业', max_length=24)
    fullname = models.CharField('股票全称', max_length=100)
    enname = models.CharField('英文全称', max_length=100)
    market = models.CharField('市场类型 （主板/中小板/创业板/科创板）', max_length=20)
    curr_type = models.CharField('交易货币', max_length=10)
    list_status = models.CharField('上市状态： L上市 D退市 P暂停上市', max_length=5)
    list_date = models.CharField('上市日期', max_length=20)
    delist_date = models.CharField('退市日期', max_length=20)
    is_hs = models.CharField('是否沪深港通标的，N否 H沪股通 S深股通', max_length=5)

class Cal(models.Model):
    exchange = models.CharField('交易所 SSE上交所 SZSE深交所', max_length=10)
    cal_date = models.CharField('日历日期', max_length=10, db_index=True)
    is_open = models.CharField('是否交易 0休市 1交易', max_length=2)
    pretrade_date = models.CharField('上一个交易日', max_length=10)

class Daily(models.Model):
    ts_code = models.CharField('TS代码', max_length=20, db_index=True)
    trade_date = models.CharField('交易日期', max_length=10, db_index=True)
    open = models.FloatField('开盘价')
    high = models.FloatField('最高价')
    low = models.FloatField('最低价')
    close = models.FloatField('收盘价')
    pre_close = models.FloatField('昨收价')
    change = models.FloatField('涨跌额')
    pct_chg = models.FloatField('涨跌幅 （未复权，如果是复权请用 通用行情接口 ）')
    vol = models.FloatField('成交量 （手）')
    amount = models.FloatField('成交额 （千元）')

class AdjFactor(models.Model):
    ts_code = models.CharField('TS代码', max_length=20, db_index=True)
    trade_date = models.CharField('交易日期', max_length=10, db_index=True)
    adj_factor = models.FloatField('复权因子')

class DailyBasic(models.Model):
    ts_code = models.CharField('TS代码', max_length=20, db_index=True)
    trade_date = models.CharField('交易日期', max_length=10, db_index=True)
    close = models.FloatField('收盘价')
    turnover_rate = models.FloatField('换手率（%）')
    turnover_rate_f = models.FloatField('换手率（自由流通股）')
    volume_ratio = models.FloatField('量比')
    pe = models.FloatField('市盈率（总市值/净利润， 亏损的PE为空）')
    pe_ttm = models.FloatField('市盈率（TTM，亏损的PE为空）')
    pb = models.FloatField('市净率（总市值/净资产）')
    ps = models.FloatField('市销率')
    ps_ttm = models.FloatField('市销率（TTM）')
    dv_ratio = models.FloatField('股息率 （%）')
    dv_ttm = models.FloatField('股息率（TTM）（%）')
    total_share = models.FloatField('总股本 （万股）')
    float_share = models.FloatField('流通股本 （万股）')
    free_share = models.FloatField('自由流通股本 （万）')
    total_mv = models.FloatField('总市值 （万元）')
    circ_mv = models.FloatField('流通市值（万元）')

# class Moneyflow_hsgt(models.Model):
#     trade_date = models.CharField('交易日期', max_length=10, db_index=True)
#     ggt_ss = models.FloatField('港股通（上海）')
#     ggt_sz = models.FloatField('港股通（深圳）')
#     hgt = models.FloatField('沪股通（百万元）')
#     sgt = models.FloatField('深股通（百万元）')
#     north_money = models.FloatField('北向资金（百万元）')
#     south_money = models.FloatField('南向资金（百万元）')
#
# class Hsgt_top10(models.Model):
#     trade_date = models.CharField('交易日期', max_length=10, db_index=True)
#     ts_code = models.CharField('TS代码', max_length=20, db_index=True)
#     name = models.CharField('股票名称', max_length=24, db_index=True)
#     close = models.FloatField('收盘价')
#     change = models.FloatField('涨跌额')
#     rank = models.IntegerField('资金排名')
#     market_type = models.CharField('市场类型（1：沪市 3：深市）', max_length=2)
#     amount = models.FloatField('成交金额（元）')
#     net_amount = models.FloatField('净成交金额（元）')
#     buy = models.FloatField('买入金额（元）')
#     sell = models.FloatField('卖出金额（元）')
#
# class Hk_hold(models.Model):
#     code = models.CharField('交易日期', max_length=10, db_index=True)
#     trade_date = models.CharField('交易日期', max_length=10, db_index=True)
#     ts_code = models.CharField('TS代码', max_length=20, db_index=True)
#     name = models.CharField('股票名称', max_length=24, db_index=True)
#     vol = models.IntegerField('持股数量(股)')
#     ratio = models.FloatField('持股占比（%），占已发行股份百分比')
#     exchange = models.CharField('类型：SH沪股通SZ深港通HK港股通', max_length=4)

# tushare基础版，pro版收费了开始
class Performance(models.Model):
    code = models.CharField('代码', max_length=10, db_index=True)
    name = models.CharField('股票名称', max_length=24, db_index=True)
    reserved_per_share = models.FloatField('每股公积金')
    eps = models.FloatField('每股收益')
    bvps = models.FloatField('每股净资')
    perundp = models.FloatField('每股未分配')

# 业绩报告（主表）
class Report_data(models.Model):
    code = models.CharField('代码', max_length=10, db_index=True)
    name = models.CharField('股票名称', max_length=24, db_index=True)
    eps = models.FloatField('每股收益')
    eps_yoy = models.FloatField('每股收益同比(%)')
    bvps = models.FloatField('每股净资')
    roe = models.FloatField('净资产收益率(%)')
    epcf = models.FloatField('每股现金流量(元)')
    net_profits = models.FloatField('净利润(万元)')
    profits_yoy = models.FloatField('净利润同比(%)')
    distrib = models.CharField('分配方案', max_length=24)
    report_date = models.CharField('发布日期', max_length=10, db_index=True)
    year = models.CharField('年份', max_length=5, db_index=True)
    quarter = models.CharField('季度', max_length=2, db_index=True)

# 个股主要指标
class Main_indicators(models.Model):
    code = models.CharField('代码', max_length=10, db_index=True)
    name = models.CharField('股票名称', max_length=24, db_index=True)
    eps = models.FloatField('每股收益')
    eps_yoy = models.FloatField('每股收益同比(%)')
    bvps = models.FloatField('每股净资')
    roe = models.FloatField('净资产收益率(%)')
    epcf = models.FloatField('每股现金流量(元)')
    operation_revenue = models.FloatField('营业收入(元)')
    operating_costs = models.FloatField('营业成本(元)')
    profit = models.FloatField('营业利润(元)')
    net_profit_to_parent = models.FloatField('归属母公司所有者净利润(元)')
    gross_profit_rate = models.FloatField('毛利率')
    operating_profit_ratio = models.FloatField('营业利润率')
    report_date = models.CharField('发布日期', max_length=10, db_index=True)

# 个股分红 根据分红*(8.5+2g)
class Bonus(models.Model):
    code = models.CharField('代码', max_length=10, db_index=True)
    name = models.CharField('股票名称', max_length=24, db_index=True)
    bonus = models.FloatField('每股收益')
    report_date = models.CharField('发布日期', max_length=10, db_index=True)
